package com.bree.erp.service.stateless;

import java.util.Collection;
import java.util.Collections;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.bree.erp.entity.Inventory;
import com.bree.erp.entity.InventoryAudit;
import com.bree.erp.entity.InventoryStatus;
import com.bree.erp.entity.Unit;
import com.bree.erp.service.InventoryAuditService;

@Stateless
public class InventoryAuditServiceBean implements InventoryAuditService {

	@PersistenceContext()
	private EntityManager em;
	
	public InventoryAuditServiceBean() {
		
	}

	public InventoryAuditServiceBean(EntityManager em) {
		this.em = em;
	}

	@Override
	public InventoryAudit create(Inventory inventory, double quantity,
			Unit unit, InventoryStatus status) {
		
		InventoryAudit inventoryAudit = new InventoryAudit();
		
		inventoryAudit.setInventory(inventory);
		inventoryAudit.setQuantity(quantity);
		inventoryAudit.setUnit(unit);
		inventoryAudit.setStatus(status);
		
		em.persist(inventoryAudit);
		return inventoryAudit;
	}

	@Override
	public InventoryAudit read(Long id) {
		
		return em.find(InventoryAudit.class, id);
	}

	@Override
	public InventoryAudit update(Long id, double quantity) {
		InventoryAudit entity = read(id);
		entity.setQuantity(quantity);
		return entity;
	}

	@Override
	public InventoryAudit update(Long id, InventoryStatus status) {
		InventoryAudit entity = read(id);
		entity.setStatus(status);
		return entity;
	}

	@Override
	public void delete(Long id) {
		InventoryAudit entity = read(id);
		em.remove(entity);
	}

	@Override
	public Collection<InventoryAudit> list() {
		
		return Collections.emptyList();
	}

}
